#include <bits/stdc++.h>
using namespace std;
inline int get_num() {
    int k = 0;
    char c = getchar();
    for(; !isdigit(c); c = getchar());
    for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k;
}
int n, m, dp[16][32];
int main() {
    m = get_num();
    n = get_num();
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][j];
        for(int j = 1; j <= n; j++) {
            int tmp = get_num();
            for(int k = j; k <= n; k++) {
                dp[i][k] = max(dp[i][k], dp[i - 1][k - j] + tmp);
            }
        }
    }
    printf("%d", dp[m][n]);
}
